'''
    该案例演示集合函数
'''
# set = set([1, 2, 3, 4, 5])
# set = {1, 2, 3, 4, 5}
# set.add(x)	添加元素
# set.add(6)
# print(set)

# set.update(x)	添加元素，x可以为列表、元组、字符串、字典等可迭代对象
# set = set([1, 2, 3, 4, 5])
# set.update(['a', 'b', 'c', 'd'])
# set.update((7, 8, 9))
# set.update("helloworld")
# print(set)

# set.union(x)	添加元素后返回一个新的集合，x可以为列表、元组、字符串、字典等可迭代对象
# set1 = {1, 2, 3, 4, 5}
# set2 = {300,400,500}
# set3 = set1.union(set2)
# print(set3)

# set.remove(x)	从集合中移除x，x不存在则报错
# set1 = {1, 2, 3, 4, 5}
# set1.remove(5)
# print(set1)
# set.discard(x) 	从集合中移除x，x不存在也不报错
# set1 = {1, 2, 3, 4, 5}
# set1.discard(6)
# print(set1)

# set.pop()	随机取出集合中的一个元素，如果集合为空则报错
# set1 = {1, 2, 3, 4, 5}
# print(set1.pop())
# print(set1)

# set.clear()	清空集合
# set1 = {1, 2, 3, 4, 5}
# set1.clear()

# set.difference(x1,...)	求set1和x1的差集，返回一个新的集合
# set1 = {100,200,300}
# set2 = {300,400,500}
# set3 = set1.difference(set2)
# set4 = set2.difference(set1)
# print(set3)  #{200, 100}
# print(set4)     #{400, 500}

# set.difference_update(x1,...)	求set1和x1的差集
# set1 = {100,200,300}
# set2 = {300,400,500}
# set1.difference_update(set2)
# set2.difference_update(set1)
# print(set1)  #{200, 100}
# print(set2)  #{400, 300, 500}

# set.intersection(x1,...)	求set1和x1的交集，返回一个新的集合
# set1 = {100,200,300}
# set2 = {300,400,500}
# set3 = set1.intersection(set2)
# print(set3)   #{300}

# set.intersection_update(x1,...)	求set1和x1的交集
# set1 = {100,200,300}
# set2 = {300,400,500}
# set1.intersection_update(set2)
# print(set1)   #{300}

# set1 & set2	两集合求交集
# set1 = {100,200,300}
# set2 = {300,400,500}
# set3 = set1 & set2
# print(set3)

# set1 | set2	两集合求并集
# set1 = {100,200,300}
# set2 = {300,400,500}
# set3 = set1 | set2
# print(set3)

# set1 - set2	两集合求差集
# set1 = {100,200,300}
# set2 = {300,400,500}
# set3 = set1 - set2
# set4 = set2 - set1
# print(set3)   #{200, 100}
# print(set4)   #{400, 500}

# set1.isdisjoint(set2)	判断两集合是否没有交集
set1 = {100,200,300}
set2 = {300,400,500}
print(set1.isdisjoint(set2))    # set1和set2的交集是300,有则返回False,没有则返回True

# set1.issubset(set2)	判断set1是否为set2的子集
set1 = {100,200,300}
set2 = {300,400,500}
print(set1.issubset(set2))    # False

# set1.issuperset(set2)	判断set2是否为set1的子集
set1 = {100,200,300}
set2 = {300,400,500}
print(set1.issuperset(set2))   # False

# set1.symmetric_difference(set2)	求两集合中不重复的元素，返回一个新的集合
set1 = {100,200,300}
set2 = {300,400,500}
set3 = set1.symmetric_difference(set2)
print(set3)   #{100, 200, 400, 500}

# set1.symmetric_difference_update(set2)	求两集合中不重复的元素
set1 = {100,200,300}
set2 = {300,400,500}
set1.symmetric_difference_update(set2)
print(set1)   #{100, 200, 400, 500}


# set.copy()	拷贝集合
set1 = {100,200,300}
set2 = set1.copy()
print(set2,id(set2))
print(set1,id(set1))

# len(set)	返回集合元素个数
set1 = {100,200,300}
print(len(set1))   #3
# max(set)	求集合中元素的最大值
set1 = {100,200,300}
print(max(set1))    # 300
# min(set)	求集合中元素的最小值
set1 = {100,200,300}
print(min(set1))    # 100
# sum(set)	求集合中元素的加和
set1 = {100,200,300}
print(sum(set1))    # 600